package com.yh.hljapp.modules.adatper;

import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.yh.hljapp.R;
import com.yh.hljapp.common.StringUtils;
import com.yh.hljapp.modules.bean.CKInfo;

import java.util.HashMap;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * @author imyar
 * @date 2015年12月2日
 */
public class CKUndoAdapter extends ListBaseAdapter<CKInfo> {
    HashMap<Integer, Boolean> state = new HashMap<Integer,Boolean>();
    static class ViewHolder {
        @InjectView(R.id.tv_ywy)
        TextView tv_ywy;
        @InjectView(R.id.tv_customername1)
        TextView tv_customername1;
        @InjectView(R.id.tv_customername2)
        TextView tv_customername2;
        @InjectView(R.id.tv_customername3)
        TextView tv_customername3;
        @InjectView(R.id.tv_customername4)
        TextView tv_customername4;
        @InjectView(R.id.tv_customername)
        TextView tv_customername;
        @InjectView(R.id.tv_time)
        TextView time;
        @InjectView(R.id.tv_title)
        TextView title;
        @InjectView(R.id.tv_description)
        TextView description;
        @InjectView(R.id.iv_statue)
        ImageView iv_statue;

        @InjectView(R.id.checkBox)
        CheckBox checkBox;
        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }

    @Override
    protected View getRealView(final int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater(parent.getContext()).inflate(
                    R.layout.list_cell_news, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.tv_customername1.setVisibility(View.GONE);
        vh.tv_customername.setVisibility(View.VISIBLE);
        vh.tv_customername2.setVisibility(View.GONE);
        vh.tv_customername3.setVisibility(View.VISIBLE);
        final CKInfo blog = mDatas.get(position);
        final String mBillNo=blog.getFBillNo();
        vh.title.setText("单号：" + mBillNo);
        vh.tv_customername.setText("订单号：" + blog.getFEntrySelfS0241());
        vh.tv_customername1.setText("产品名称：" + blog.getProutName());
//            vh.tv_customername2.setText("数量："+blog.getExpr1());
        vh.tv_customername3.setText("客户名称：" + blog.getCustomerName());
//            vh.tv_customername4.setText("总金额："+blog.getAllMoney()+"元");
        vh.description.setVisibility(View.GONE);
        vh.tv_ywy.setVisibility(View.GONE);
        vh.checkBox.setVisibility(View.VISIBLE);
        vh.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    state.put(position, isChecked);
                }else {
                    state.remove(position);
                }
                blog.setFwgtype(isChecked);
            }
        });
        vh.checkBox.setChecked(state.get(position)==null? false : true);
        blog.setFwgtype(state.get(position)==null? false : true);
        String time = blog.getFFetchDate();
        if (!StringUtils.isEmpty(time)) {
            if (time.indexOf(".") > -1) {
                vh.time.setText(time.replace("T", " ").substring(0, time.indexOf(".")));
            } else {
                vh.time.setText(time.replace("T", " "));
            }
        }

        return convertView;
    }
}
